package request

import "go.didapinche.com/foundation/plat-echo/app/ops/models"

type TempUpdate struct {
	TempID   uint64 `json:"temp_id"`
	Name     string `form:"name"`
	Eq       bool   `form:"eq"`
	PageNum  int    `form:"page_num"`
	PageSize int    `form:"page_size"`
}

//type SubscribeReq struct {
//	ID        uint64 `json:"id"`
//	Subscribe bool   `form:"subscribe" json:"subscribe"`
//	*models.SubscribeInfo
//}

type TemplateReq struct {
	ID            uint64                `json:"id" form:"id"`
	GraphType     string                `form:"-" json:"-"`
	Queries       models.Queries        `form:"queries" json:"queries"`
	Alert         *models.Alert         `form:"alert"  json:"alert"`
	General       *TemplateGeneral      `form:"general" json:"general"`
	All           int                   `form:"all" json:"all"`
	Type          UpdateType            `form:"type" json:"type"`
	Visualization *models.Visualization `form:"visualization" json:"visualization"`
	AppID         uint64                `gorm:"-" json:"app_id"`
	ApiID         uint64                `gorm:"-" json:"api_id"`
	HostID        uint64                `gorm:"-" json:"host_id"`
}

type UpdateType int

const (
	All      UpdateType = 1
	Update   UpdateType = 2
	UnUpdate UpdateType = 3
)

type TemplateGeneral struct {
	Name     string       `form:"name" json:"name"`
	TypeID   uint64       `form:"type_id"  json:"type_id"`
	TypeName string       `form:"type_name"  json:"type_name"`
	Order    int          `form:"order"  json:"order"`
	Tag      string       `form:"tag" json:"tag"`
	Kind     int          `json:"kind" form:"kind"`
	Sla      bool         `form:"sla" json:"sla"`
	Yaxes    models.Yaxes `form:"yaxes" json:"yaxes"`
}

// 前端数据转化为后端
func (t *TemplateReq) Change() *models.Template {
	template := new(models.Template)
	template.ID = t.ID
	if t.General != nil {
		template.Sla = t.General.Sla
		template.Order = t.General.Order
		template.Name = t.General.Name
		template.General = &models.General{Yaxes: t.General.Yaxes}
		template.Kind = models.GraphKind(t.General.Kind)
		template.TypeID = t.General.TypeID
	}
	template.Type = int(t.Type - 1)
	template.AppID = t.AppID
	template.ApiID = t.ApiID
	template.HostID = t.HostID
	template.Visualization = t.Visualization
	template.Alert = t.Alert
	template.Queries = t.Queries

	return template
}
